package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.ydd.entity.Cate;
import com.itheima.ydd.entity.Link;
import com.itheima.ydd.mapper.LinkMapper;
import com.itheima.ydd.service.LinkService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link> implements LinkService {
    @Override
    public HashMap<String, Object> getPageHashMap(String type, Integer page, Integer limit) {
        Page<Link> linkPage = new Page<>(page, limit);
        LambdaQueryWrapper<Link> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Link::getType, type);
        this.page(linkPage, lqw);
        List<Link> records = linkPage.getRecords();
        Integer count = this.count(lqw);
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", count);
        map.put("currentPage", page);
        map.put("pageSize", limit);
        map.put("totalPages", linkPage.getTotal());
        map.put("data", records);
        return map;
    }
}
